<?php
if(!isset($_POST['cmd']) && (!isset($_POST['id'])))
{
	$cmd 	= $_POST['cmd'];
	$id		= $_POST['id'];
	
	// Declaration
	$data	= array();
	
	// Based on the ID, get the State of the character
	//$current_state = getState();
	$current_state = "battle";
	
	// If the state of the character does not allow the following command, ignore the command immediately with the message
	//$check_next_state = checkState($current_state, $cmd);
	$check_next_state = TRUE;
	
	if($check_next_state)
	{
		// State is valid, now perform the logic
		$data['valid'] = "true";
		
		// The logic is divided into several categories
		/*
			Example:
			1. Battle (Attack, Defense, Skills, Use Items)
			2. Field (Move between Fields)
			3. Farming / Mining / Gathering
		*/
		
		switch($current_state)
		{
			case "battle":
				// Apply Battle Function
			break;
			
			case "field":
				// Apply Field Function
			break;
			
			case "farming":
				// Apply Farming Function
			break;
			
			default: 
				$data['valid'] = "false";
				$data['msg'] = "Unknown State >> " . $current_state;
			break;
		}
	}
	else
	{
		$data['valid'] = "false";
		$data['msg'] = "The command that you selected are forbidden in your current state";
	}
}

// This should be moved later
function battle($command, $target)
{
	switch($command)
	{
		case "attack": break;
	}
}

header('Content-Type: application/json');
echo json_encode($data);
?>